import request from '@/utils/request'
import {parseStrEmpty} from "@/utils/ruoyi";

export function getUser(userId) {
  return request({
    url: '/system/user/' + parseStrEmpty(userId),
    method: 'get'
  })
}

export function searchDebt(query){
  return request({
    url: 'system/debt/search',
    method: 'get',
    params: query
  })
}
// 查询用户列表
export function listUser(query) {
  return request({
    url: '/system/user/list',
    method: 'get',
    params: query
  })
}
// 查询欠款账单
export function listDebt(query){
  return request({
    url: '/system/user/listdebt',
    method: 'get',
    params: query
  })
}
//新增欠款账单
export  function addDebt(data){
  return request({
    url: '/system/debt/addDebt',
    method: 'post',
    data: data
  })
}
/**
 * 删除欠款账单
 * @param debt
 * @returns {AxiosPromise<AxiosResponse<any>>}
 */
export function removeDebt(debt){
  return request({
    url: '/system/debt/removeStatus',
    method: 'put',
    data: debt
  })
}
//修改欠款账单
export function updateDebt(debt){
  return request({
    url: '/system/debt/updateDebt',
    method: 'post',
    data: debt
  })
}
//改变账单状态为收款
export function payeeDebt(debt){
  return request({
    url: '/system/debt/payee',
    method: 'put',
    data: debt
  })
}
//查询账单详细
export function getDebt(id){
  return request({
    url: '/system/debt/getDebt/' + id,
    method: 'get',
  })
}
// 查询用户个人信息
export function getUserProfile() {
  return request({
    url: '/system/user/profile',
    method: 'get'
  })
}

// 修改用户个人信息
export function updateUserProfile(data) {
  return request({
    url: '/system/user/profile',
    method: 'put',
    data: data
  })
}

// 用户密码重置
export function updateUserPwd(oldPassword, newPassword) {
  const data = {
    oldPassword,
    newPassword
  }
  return request({
    url: '/system/user/profile/updatePwd',
    method: 'put',
    params: data
  })
}

// 用户头像上传
export function uploadAvatar(data) {
  return request({
    url: '/system/user/profile/avatar',
    method: 'post',
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    data: data
  })
}

// 查询授权角色
export function getAuthRole(userId) {
  return request({
    url: '/system/user/authRole/' + userId,
    method: 'get'
  })
}

// 保存授权角色
export function updateAuthRole(data) {
  return request({
    url: '/system/user/authRole',
    method: 'put',
    params: data
  })
}
